package com.xszx.knowledge.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xszx.knowledge.dto.PageReq;
import com.xszx.knowledge.entity.Content;
import com.xszx.knowledge.mapper.DocMapper;
import com.xszx.knowledge.service.ContentService;
import com.xszx.knowledge.service.DocService;
import com.xszx.knowledge.util.Result;
import io.swagger.annotations.*;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;

/**
 * <p>
 * 文档内容 前端控制器
 * </p>
 *
 * @author wencai
 * @since 2023/04/26 11:24
 */
@Api(tags = "文档内容管理")
@RestController
@RequestMapping("/content")
public class ContentController {
    @Resource
    private ContentService contentService;
    @Resource
    private DocService docService;
    /**
     * 根据文档id查询对应的内容数据
     * @return
     */

    @ApiOperation(value = "查询文档内容", notes = "根据电子书ID查询电子书对应的文章内容")
    @GetMapping("/getContentById")
    public Result getContentById(long id,String type){
        Content content =contentService.getById(id);
        //进行阅读数的更新(前端人员查看并且有文章内容)
        if(!"back".equals(type) && !ObjectUtils.isEmpty(content) ){//阅读数加1  必须有文档内容
            docService.updateViewCount(id);
        }
        return (ObjectUtils.isEmpty(content))?Result.error():Result.ok(content);
    }
}
